package com.test.month_2020_04.day_03;

import java.util.concurrent.locks.LockSupport;

public class T02_00_LockSupport {
    static Thread t1 = null;
    static Thread t2 = null;

    public static void main(String[] args) {
        char[] chars1 = "abcdefg".toCharArray();
        char[] chars2 = "1234567".toCharArray();

        t1 = new Thread(()->{
            for (Character c : chars1){
                System.out.println(c);
                LockSupport.unpark(t2);//叫醒t2
                LockSupport.park();//t1阻塞
            }
        },"t1");

        t2 = new Thread(()->{
            for (Character c : chars2){
                LockSupport.park();//t2阻塞
                System.out.println(c);
                LockSupport.unpark(t1);//叫醒t1
            }
        },"t2");

        t1.start();
        t2.start();
    }
}